package com.gr.experimental.model.impl.distr.operations;

import com.gr.experimental.model.impl.distr.Action;
import com.gr.experimental.model.impl.distr.Assignable;
import com.gr.experimental.model.impl.distr.AssignmentException;
import com.gr.experimental.model.impl.distr.Context;

public class AssignAction implements Action {

	Assignable assignable;
	Expression expression;

	/**
	 * @param assignable
	 * @param expression
	 */
	public AssignAction(Assignable assignable, Expression expression) {
		this.assignable = assignable;
		this.expression = expression;
	}

	/**
	 * {@inheritDoc}
	 * @throws PerformActionException 
	 * @see com.gr.experimental.model.impl.distr.Action#perform()
	 */
	@Override
	public void perform(Context context) throws PerformActionException {
		try {
			assignable.assign(context, expression.getValue(context));
		} catch (CalculationException e) {
			throw new PerformActionException(e);
		} catch (AssignmentException e) {
			throw new PerformActionException(e);
		}
	}
	

}
